package com.gupaoedu.mybatis.mywant;

import com.gupaoedu.mybatis.my.TestMapperXml;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MapperProxy<T> implements InvocationHandler {
    private  Class calzz;
    private  MySqlSession sqlSession;
    public MapperProxy(MySqlSession sqlSession, Class<T> calzz) {

        this.sqlSession=sqlSession;
        this.calzz=calzz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
       if (method.getDeclaringClass().getName().equals(Configaration.TestMapperXML.nameSpace)){
           String sql = (String) Configaration.TestMapperXML.Mapper.get(method.getName());//获得sql

           System.out.println(String.format("SQL [ %s ], parameter [%s] ", sql, args[0]));
           return sqlSession.selectOne(sql, String.valueOf(args[0]));

       }
       return  null;
    }
}
